﻿using System.Collections.Generic;
using System.Threading;
using Microsoft.AspNet.SignalR.Hubs;
using Sportsbook.Domain.Models.Lines;
using Sportsbook.Domain.Repositories;

namespace Sportsbook.Website.Tickers
{
    public class LinesTicker
    {
        private readonly IHubConnectionContext clients;
        private readonly ILinesRepository repository;
        private readonly Timer timer;

        public LinesTicker(IHubConnectionContext clients, ILinesRepository repository)
        {
            this.clients = clients;
            this.repository = repository;
            timer = new Timer(SendLines, null, 1000, 1000);
        }

        private void SendLines(object state)
        {
            var lines = repository.Get();
            clients.All.sendLines(lines);
        }
    }
}